<template>
  <!-- 5 lx人气推荐 -->
  <div class="breadcrumb">
    <Breadcrumb :aaa="aaa" :msgg="msg" :txt="txt" :path1="path1" />
  </div>
  <div class="box">
    <!-- <navTitle title="人气推荐"></navTitle> -->
    <seartch :array="array"></seartch>
    <dataList :datalisttitle="datalisttitle"></dataList>
    <!-- 推荐列表  此列表传递内容进入其中 和外界进行交互 多是利用父子传递参数 -->
    <comment
      v-model:state="commendListState"
      :total="total"
      v-model:pageNum="pageNum"
      v-model:pageSize="pageSize"
      @updateAX="AX"
      @DeleteLists="DeleteLists"
      @update="update"
    >
    </comment>
  </div>
</template>

<script lang="ts" setup>
import navTitle from "../../components/home/NavTitle.vue";
import seartch from "../../components/home/Serch.vue";
import dataList from "../../components/home/DataList.vue";
import comment from "../../components/home/BrandRecommend.vue";
import { flash } from "../../request/api";
import { ref } from "vue";
import Breadcrumb from "../../components/breadcrumb.vue";
let msg = ref("人气推荐");
let txt = ref("营销");
let path1 = ref("sms/flash");
let aaa = ref(0);

let array = [
  {
    title: "商品名称",
    havelist: false,
    placeholder: "商品名称",
  },
  {
    title: "推荐状态",
    placeholder: "全部",
    havelist: true,
    appNameList: ["未推荐", "推荐中"],
  },
];
let datalisttitle = [
  //传给数据列表的内容
  {
    val: "选择商品",
  },
];
// 列表数据
// 推荐列表的列表数据
let pageSize = ref(5); //几条数据
let pageNum = ref(1); // 第几页
let total = ref(1); // 全部几条数据
let commendListState = ref([]); //具体数据列表
function DeleteLists(e: Array<number>) {
  //删除函数
  let z = e.toString();
  flash.deleteRecommendProductList(z).then((res) => {
    AX();
  });
}
function AX() {
  flash
    .recommendProductList({
      pageNum: pageNum.value,
      pageSize: pageSize.value,
    })
    .then((res) => {
      // 更新上面5条数据
      let newlist = [];
      for (let i = 0; i < res.list.length; i++) {
        newlist.push({
          brandId: res.list[i].productId,
          brandName: res.list[i].productName,
          id: res.list[i].id,
          recommendStatus: res.list[i].recommendStatus,
          sort: res.list[i].sort,
        });
      }
      pageSize.value = res.pageSize;
      pageNum.value = res.pageNum;
      commendListState.value = newlist;
      total.value = res.total;
    });
}
AX();

// 推荐状态修改函数
function update(e: number | Array<number>, i: 1 | 0 | 100) {
  flash
    .updaterecommendProductStatus({
      ids: e.toString(),
      recommendStatus: -i + 1,
    })
    .then((res) => {
      AX();
    });
}
</script>

<style lang="scss" scoped>
.box {
  margin: 20px;
}
</style>
